package com.gpzx.zx.module.home.frame.view

import android.content.Context
import android.view.View
import androidx.recyclerview.widget.LinearLayoutManager
import com.bumptech.glide.Glide
import com.gpzx.zx.R
import com.gpzx.zx.module.home.frame.model.QKLNewsInfo
import com.gpzx.zx.module.home.ui.activity.AuthorActivity
import com.gpzx.zx.module.home.ui.activity.InfoWebViewActivity
import com.gpzx.zx.module.home.ui.adapter.QklNewsAdapter
import com.qmuiteam.qmui.widget.QMUITopBar
import com.wkq.base.frame.mosby.delegate.MvpView

import com.wkq.lib_base.adapter.KtDataBindingAdapter
import com.wu.common.utils.StatusBarUtil

/**
 *
 * 作者:吴奎庆
 *
 * 时间:2020/7/14
 *
 * 用途:
 */


class AuthorView : MvpView {
    var mActivity: AuthorActivity
    var toolbar: QMUITopBar? = null
    var mAdapter: QklNewsAdapter? = null

    constructor(activity: AuthorActivity) {
        mActivity = activity
    }


    fun initToolBar(title: String) {
        StatusBarUtil.setStatusBarDarkMode(mActivity)
        StatusBarUtil.setColor(mActivity, mActivity!!.getResources().getColor(R.color.color_2b2b2b), 0)
        toolbar = mActivity!!.binding.includeToolbar as QMUITopBar
        toolbar?.setTitle(title)
        toolbar?.setBackgroundColor(mActivity!!.resources.getColor(R.color.color_2b2b2b))
        toolbar?.addLeftImageButton(R.drawable.ic_arrow_back_white_24dp, R.id.qmui_topbar_item_left_back)?.setOnClickListener { mActivity!!.finish() }
    }

    fun showView(orgInfo: List<QKLNewsInfo>) {
        showTopInfo(orgInfo.get(0))
        mAdapter!!.addItems(orgInfo.toMutableList())

    }

    private fun showTopInfo(orgInfo: QKLNewsInfo) {

        Glide.with(mActivity).load(orgInfo?.news_author_icon).into(mActivity.binding.ivIcon)
        mActivity.binding.tvName.setText(orgInfo.news_author_name)
        mActivity.binding.tvType.setText(orgInfo.news_type)
        mActivity.binding.tvType.setText(orgInfo.news_type)
        mActivity.binding.tvDesc.setText(orgInfo.news_author_desc)
    }

    fun initView() {
        initToolBar("知名博主")
        mActivity.binding.rvContent.layoutManager = LinearLayoutManager(mActivity)
        mAdapter = QklNewsAdapter(mActivity as Context, R.layout.item_qkl_news_info)
        mActivity.binding.rvContent.adapter = mAdapter

        mAdapter!!.setOnViewClickListener(object : KtDataBindingAdapter.OnAdapterViewClickListener<QKLNewsInfo> {
            override fun onViewClick(v: View?, program: QKLNewsInfo?) {
                InfoWebViewActivity().newInstance(mActivity as Context, "qkl_author_news", program?.id, program?.news_title)
            }
        })
    }


}